class PlayerRaceController extends SimplePC;

function PlayerTick(float DeltaTime)
{
	Super(GamePlayerController).PlayerTick(DeltaTime);
}

state PlayerDriving
{
ignores SeePlayer, HearNoise, Bump;

	function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot);

	function ProcessDrive(float InForward, float InStrafe, float InUp, bool InJump)
	{
		local Vehicle CurrentVehicle;

		CurrentVehicle = Vehicle(Pawn);

		if (CurrentVehicle != None)
		{
			bPressedJump = InJump;
			CurrentVehicle.SetInputs(InForward, -InStrafe, InUp);
			CheckJumpOrDuck();
		}
	}

	function PlayerMove(float DeltaTime)
	{
		local float Forward, Strafe;

		//UpdateRotation(DeltaTime);

		// Get the forward input information
		Forward = PlayerInput.aForward;
		// Get the strafe input information
		Strafe = PlayerInput.aStrafe;

		if (PlayerInput != None)
		{
			//Movement = 1.f;
			Forward = PlayerInput.aForward;//(((PlayerInput.aTilt.X * UnrRotToDeg) - 30.f) / 20.f) * -1.f;
			Strafe = (PlayerInput.aTilt.Z * UnrRotToDeg) / 20.f;
		}

		// Clamp the forward to within -1.f and 1.f
		Forward = FClamp(Forward, -1.f, 1.f);
		// Clamp the strafe to within -1.f and 1.f
		Strafe = FClamp(Strafe, -2.f, 2.f);

		ProcessDrive(Forward, Strafe, PlayerInput.aUp, bPressedJump);

		if (Role < ROLE_Authority)
		{
			ServerDrive(PlayerInput.aForward, PlayerInput.aStrafe, PlayerInput.aUp, bPressedJump, ((Rotation.Yaw & 65535) << 16) + (Rotation.Pitch & 65535));
		}

		bPressedJump = false;
	}

	event BeginState(Name PreviousStateName)
	{
		CleanOutSavedMoves();
	}

	event EndState(Name NextStateName)
	{
		CleanOutSavedMoves();
	}

	event InitInputSystem()
	{
	   Super.InitInputSystem();

	   //Get a reference to the local MobilePlayerInput
	   MPI = MobilePlayerInput(PlayerInput);
   
	   //Assing the input handler function to the delegate
	   MPI.OnInputTouch = HandleInputTouch;

	   //get the screen dimensions (used to transform to relative screen coords for the DeProject)
	   LocalPlayer(Player).ViewportClient.GetViewportSize(ViewportSize);
	}
	
	//delegate     OnInputTouch(int Handle, EZoneTouchEvent Type, Vector2D TouchLocation, float DeviceTimestamp, int TouchpadIndex);
	function HandleInputTouch(int Handle, EZoneTouchEvent Type, Vector2D TouchLocation, float DeviceTimestamp, int TouchpadIndex)
	{
		`log("INPUT HANDLE");
		WorldInfo.Game.Broadcast(self,"INPUT HANDLE");		

		if(Type == ZoneEvent_Touch)
		{    
			//ProcessDrive(Forward, Strafe, PlayerInput.aUp, bPressedJump);
			//ProcessDrive(10,0,0,0);
			`log("Touch");
		}
		else if(Type == ZoneEvent_Update)
		{
			//you are touching the screen 
			`log("Update");
		}
		else if(Type == ZoneEvent_Untouch)
		{
			//ProcessDrive(10,0,0,0);
			`log("Untouch");
		}

	}

}

DefaultProperties
{
}

/*function UpdateRotation( float DeltaTime )
{
	local Rotator	DeltaRot, newRotation, ViewRotation;

        // Change the view to match the rotation of the pawn, instead
	if (Pawn!=none)
	{
		ViewRotation = Pawn.Rotation;
	}


	ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
	SetRotation(ViewRotation);

	ViewShake( deltaTime );

	NewRotation = ViewRotation;
	NewRotation.Roll = Rotation.Roll;

	if ( Pawn != None )
		Pawn.FaceRotation(NewRotation, deltatime);
}*/